package algorithm;

public class Test3 {
    public static void main(String[] args) {
        int[] arr = {5, 13, 27, 34, 51, 77};
        System.out.println(binarySearch(arr, 34));
    }

    public static int binarySearch(int[] arr, int date) {
        int left = 0;
        int right = arr.length - 1;


        while (left <= right) {
            int middle = (left + right) / 2;
            if (date < arr[middle]) {
                right = middle - 1;
            } else if (date > arr[middle]) {
                left = middle + 1;
            } else {
                return middle;
            }
        }
        return -1;
    }
}
